/* Created July 23, 2006.
 * Copyright (c) 2006, George Wright (geo@loyola.edu)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright notice, 
 *       this list of conditions and the following disclaimer.
 * 
 *     * Redistributions in binary form must reproduce the above copyright 
 *       notice, this list of conditions and the following disclaimer in the 
 *       documentation and/or other materials provided with the distribution.
 * 
 *     * Neither the name of George Wright nor the name of Loyola College
 *       may be used to endorse or promote products derived from this software 
 *       without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 * 
 * To learn more about open source licenses, please visit: 
 * http://opensource.org/index.php
 * 
 * changed by Vladimir Iglovikov
 */
package common;

import javax.swing.JOptionPane;

/**
 * Standard, all-purpose exception for arima package routines. Displays a dialog
 * box at the console.
 * <p>
 * $Id: ForecastException.java,v 1.1 2008/07/02 12:48:56 Geo Exp $
 * </p>
 */
public class ForecastException extends Throwable {
	/**
	 * Ultimate handler for all exceptions. Displays a dialog box.
	 * 
	 * @param theException
	 *            arima.ArimaException
	 */
	public static void handleException(ForecastException theException) {
		// TODO delete printStackTrace after development
		theException.printStackTrace();
		JOptionPane.showMessageDialog(null, theException.getMessage(),
				Constants.STRINGS.getString("Exception.name"),
				JOptionPane.ERROR_MESSAGE);
	}

	/**
	 * Default constructor.
	 */
	public ForecastException() {
		super();
	}

	/**
	 * Constructor with single argument.
	 * 
	 * @param message
	 *            java.lang.String
	 */
	public ForecastException(String message) {
		super(message);
	}

	/**
	 * Constructor with two arguments.
	 * 
	 * @param message
	 *            java.lang.String
	 * @param throwable
	 *            java.lang.Throwable
	 */
	public ForecastException(String message, Throwable throwable) {
		super(message, throwable);
	}

	/**
	 * Indicates whether some other object is "equal to" this one.
	 * 
	 * @param obj
	 *            Object
	 * @return whether or not the argument equals the caller
	 */
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (!(obj instanceof ForecastException))
			return false;
		ForecastException newArimaException = (ForecastException) obj;
		if (!this.getMessage().equals(newArimaException.getMessage()))
			return false;
		if (this.getCause() != null && newArimaException.getCause() != null) {
			if (!this.getCause().equals(newArimaException.getCause()))
				return false;
		}
		if (this.getCause() == null && newArimaException.getCause() == null)
			return true;
		return true;
	}
}